﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DBA.Data;
using DBA.Data.Hibernate;
using DBA.Model;


namespace Demo
{
    public partial class demo_page3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("UserName", "");
            Bind(1, null);
        }



        NHibernateQuery dal = CommonQuery.NHibernateQuery;

        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("UserName", txtMemberId.Text.Trim());
            ViewState["conditions"] = dict;
            Bind(1, dict);
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IDictionary<String, String> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IDictionary<String, String>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, dict);
        }

        private void Bind(int pageIdx, IDictionary<String, String> dict)
        {
            List<Condition> conList = new List<Condition>();
            int count = 0;
            if (dict == null)
            {
                count = dal.GetMaxCount<Test_UserInfo>(null);
                replData.DataSource = dal.SelectObjects<Test_UserInfo>(null, pageIdx, 20);
            }
            else
            {
                conList.Add(new Condition("UserName", Op.Like, dict["UserName"].ToString()));
                count = dal.GetMaxCount<Test_UserInfo>(conList.ToArray());
                replData.DataSource = dal.SelectObjects<Test_UserInfo>(conList.ToArray(), pageIdx, 20);
            }
            replData.DataBind();
            AspNetPager1.RecordCount = count;
        }

        protected void linkBtnMaskSearch_Click(object sender, EventArgs e)
        {
            //IDictionary<String, String> dict = new Dictionary<String, String>();
            //dict.Add("UserName", txtMaskMemberId.Text.Trim());
            //ViewState["conditions"] = dict;
            //Bind(1, dict);
        }

        protected void linkBtnDeleSelect_Click(object sender, EventArgs e)
        {
            //if (!String.IsNullOrEmpty(hidDeleString.Value))
            //{
            //    string value = hidDeleString.Value;
            //    string sql = "delete from [test_UserInfo] where UserID in (" + value + ");";
            //    dal.ExecuteNonQuery(sql);
            //    if (String.IsNullOrEmpty(dal.ErrorMessage))
            //    {
            //        Bind(1, null);
            //        ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.correct('数据删除成功');", true);
            //    }
            //    else
            //    {
            //        ScriptManager.RegisterStartupScript(this, base.GetType(), "deleOk" + System.Guid.NewGuid().ToString(), "parent.alertMsg.error('数据删除失败');", true);
            //    }
            //}
        }

    }
}